<%@page pageEncoding="UTF-8" %><?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<%
org.sysmo.server.SysmoServer server = (org.sysmo.server.SysmoServer)application.getAttribute("sysmoServer");
org.sysmo.server.node.AddedNode currentNode = server.getNode(Integer.parseInt(request.getParameter("nid")));
request.setAttribute("currentNode", currentNode);
%>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <link rel="stylesheet" media="screen,projection" type="text/css" href="css/reset.css" />
    <link rel="stylesheet" media="screen,projection" type="text/css" href="css/main.css" />
    <!--[if lte IE 6]><link rel="stylesheet" type="text/css" href="css/main-msie.css" /><![endif]-->
    <link rel="stylesheet" media="screen,projection" type="text/css" href="css/style.css" />
    <%--<link rel="stylesheet" media="print" type="text/css" href="css/print.css" />--%>

    <title><%= currentNode.getName() %> - sysmo</title>
    <script src="js/lightbox.js" type="text/javascript"></script>
    <script src="js/util.js" type="text/javascript"></script>
    <script type="text/javascript">
        <!--

        var itemBox;
        var isShowHelp = false;

        function showHelp() {
            itemBox.Close();
            if (isShowHelp) {
                $("helpInfo").style.display = "none"
                isShowHelp = false;
            } else {
                $("helpInfo").style.display = ""
                isShowHelp = true;
            }
            itemBox.Show();
        }

        function deleteItem(id, name) {
            if (confirm("确实要删除监控项 " + name + " 吗？")) {
                window.location = "DeleteItem.do?iid=" + id;
            }
        }

        function onShowBox() {
            $("downloadScript").innerHTML = "";
            $("lightBoxTitle").innerHTML = "新增监控项";
            $("name").focus();
        }

        function onCloseItem() {
            $("lightBoxTitle").innerHTML = "新增监控项";
            $("name").value = "";
            $("timeInterval").value = "60";
            $("cscript").value = "";
            $("vscript").value = "";
            $("warningEmail").value = "";
            $("commandLine").value = "\${file}";
            $("iid").value = "0";
        }

        function onItemSubmit() {
            if ($("name").value == "") {
                alert("请输入监控项名称");
                $("name").focus();
                return false;
            }
            if ($("timeInterval").value == "" || !$("timeInterval").value.match("[0-9]+")) {
                alert("请输入采集时间间隔，为正整数");
                $("timeInterval").focus();
                return false;
            }
            return true;
        }

        <%
        if (request.getAttribute("error") != null) {
        %>
            alert("<%= org.sysmo.server.util.UtilHelper.encodeJSString((String)request.getAttribute("error")) %>");
        <%
        }
        %>
            
        -->
    </script>
</head>

<body>

<div id="main">

    <!-- Header -->
    <div id="header">
    
        <p id="logo">sysmo</p>
        
        <div id="slogan">A distributed system monitor tool</div>
    
    </div> <!-- /header -->
    
    <hr class="noscreen" />
    
    <!-- Navigation -->
    <div id="nav" class="box">
    
        <ul>
            <li class=""><a href="AllNodes.do">监控列表</a></li>
            <li class=""><a href="NewNodes.do">新增客户端</a></li>
            <li class="active"><a href="Node.do?nid=<%= currentNode.getID() %>">节点(<%= currentNode.getName() %>)</a></li>
            <li class=""><a href="Users.do">用户管理</a></li>
            <li class=""><a href="Logout.do">退出登录(<%= ((org.sysmo.server.user.User)session.getAttribute("user")).getName() %>)</a></li>
        </ul>
    
    </div> <!-- /nav -->
    
    <hr class="noscreen" />
    
    <!-- Columns -->
    <div id="cols">
        <div id="cols-in" class="box">
    
            <!-- Content -->
            <div id="content">
                
                <h2 class="title-01"><%= currentNode.getName() %><%= currentNode.isConnected() ? "" : "(未连接)" %></h2>
                
                <div class="in">
                
                    <!-- Topstory -->
                    <div class="box">
                        <div id="topstory-txt">
                            <%
                            if (currentNode.isConnected()) {
                            %>
                            <p><a href="#" id="addItem">增加新监控项</a></p>
                            <%
                            }
                            %>
                            <table class="main_table">
                            <%
                            java.util.List<org.sysmo.server.node.item.Item> items = currentNode.getAllItems();
                            for (org.sysmo.server.node.item.Item item : items) {
                            %>
                                <tr>
                                    <td><a href="Item.do?iid=<%= item.getID() %>"><%= item.getName() %></a></td>
                                    <td>
                                        <% if (currentNode.isConnected()) { %><a href="StartEditItem.do?iid=<%= item.getID() %>">编辑</a>&nbsp;&nbsp;&nbsp;&nbsp;<% } %>
                                        <a href="javascript:deleteItem(<%= item.getID() %>, '<%= org.sysmo.server.util.UtilHelper.encodeJSString(item.getName()) %>')">删除</a>
                                    </td>
                                </tr>
                            <%
                            }
                            %>
                            </table>
                            <p>总监控项数：<%= items.size() %></p>
                        </div> <!-- /topstory-txt -->
                        
                    </div> <!-- /box -->

                    <a name="warning"></a>
                    <h4 class="title-02"><span>此节点警告（单击警告信息以删除）</span></h4>

                    <div class="box">
                        <table class="main_table">
                            <thead>
                                <th>警告信息</th>
                                <th>节点</th>
                                <th>监控项</th>
                                <th>图表</th>
                                <th>监控值</th>
                                <th>警告时间</th>
                            </thead>
                            <%
                            java.util.List<org.sysmo.server.node.item.Warning> warnings = currentNode.getAllWarnings();
                            java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
                            for (org.sysmo.server.node.item.Warning warning : warnings) {
                            %>
                            <tr>
                                <td><a href="DeleteWarning.do?re=1&reid=<%= currentNode.getID() %>&wid=<%= warning.getID() %>"><%= warning.getMessage() %></a></td>
                                <td><%
                                try {
                                    org.sysmo.server.node.AddedNode node = server.getNode(warning.getNodeID());
                                    out.print("<a href=\"Node.do?nid=" + node.getID() + "\">" + node.getName() + "</a>");
                                } catch (org.sysmo.server.node.NodeNotExistsException e) {
                                    out.print("未知节点");
                                }
                                %></td>
                                <td><%
                                try {
                                    org.sysmo.server.node.item.Item item = server.getItem(warning.getItemID());
                                    out.print("<a href=\"Item.do?iid=" + item.getID() + "\">" + item.getName() + "</a>");
                                } catch (org.sysmo.server.node.item.ItemNotExistsException e) {
                                    out.print("未知监控项");
                                }
                                %></td>
                                <td><%
                                try {
                                    org.sysmo.server.node.item.graphgroup.GraphGroup graph = server.getGraphGroup(warning.getGraphID());
                                    out.print("<a href=\"EditGraph.do?gid=" + graph.getID() + "\">" + graph.getName() + "</a>");
                                } catch (org.sysmo.server.node.item.graphgroup.GraphGroupNotExistsException e) {
                                    out.print("未知图表");
                                }
                                %></td>
                                <td><%
                                try {
                                    org.sysmo.server.node.item.graphgroup.value.Value value = server.getValue(warning.getValueID());
                                    out.print("<a href=\"EditGraph.do?gid=" + value.getParentID() + "\">" + value.getName() + "</a>");
                                } catch (org.sysmo.server.node.item.graphgroup.value.ValueNotExistsException e) {
                                    out.print("未知监控值");
                                }
                                %></td>
                                <td><%= fmt.format(warning.getTime()) %></td>
                            </tr>
                            <%
                            }
                            %>
                        </table>
                    </div>

                </div> <!-- /in -->
                
            </div> <!-- /content -->

            <hr class="noscreen" />

            <!-- Aside -->
            <div id="aside">

                <h4 class="title-03">操作流程</h4>
                
                <div class="in">
                    <ul id="subnav">
                        <li><a href="#">部署客户端程序和配置文件</a></li>
                        <li><a href="NewNodes.do">单击此处将新客户端加入监控列表</a></li>
                        <li><a href="#">创建监控项、图表项和监控值</a></li>
                        <li><a href="#">配置监控项、上传数据采集程序</a></li>
                        <li><a href="#">查看图表，获取最新数据</a></li>
                        <%--<li><a href="#">Lorem ipsum sit amet</a></li>
                        <li><a href="#">Lorem ipsum sit amet</a></li>
                        <li class="active"><a href="#">Lorem ipsum sit amet</a></li>
                        <li><a href="#">Lorem ipsum sit amet</a></li>
                        <li><a href="#">Lorem ipsum sit amet</a></li>
                        <li class="last"><a href="#">Lorem ipsum sit amet</a></li>--%>
                    </ul>

                </div> <!-- /in -->

            </div> <!-- /aside -->
            
        </div> <!-- /cols-in -->
    </div> <!-- /cols -->

    <hr class="noscreen" />
    
    <!-- Footer -->
    <div id="footer" class="box">
        
        <p class="f-left"><a href="http://sysmo.googlecode.com">sysmo @ GoogleCode</a></p>

    </div> <!-- /box -->

</div> <!-- /main -->

<dl id="lightBox">
    <dt id="lightBoxTitle">新增监控项</dt>
    <dd id="lightBoxText">
        <html:form action="EditItem.do?nid=${currentNode.ID}" method="POST" enctype="multipart/form-data" onsubmit="javascript:return onItemSubmit()">
            <a href="javascript:showHelp();">&lt;&lt;切换显示帮助信息</a>
            <div id="helpInfo" style="display:none;width:400px;">
            <p>数据采集脚本为客户端系统可执行的程序或脚本文件。此脚本应立即从标准输出返回采集到的对应于服务器上的图表项和监控值的数据，每行一个数据。<br />
            每行数据的格式为“图表名__监控值名=数据值”，数据值为整数。例如在名为cpu的图表中包含了idle、user和kernel三个监控值，则对应的脚本返回的内容应为<br />
            cpu__idle=90<br />cpu__user=6<br />cpu__kernel=4<br />
            请输入数据采集命令行来执行此脚本，可用\${file}替代此脚本文件名。例如执行JAR文件命令行为“java -jar \${file}”。<br />
            数据验证脚本为JavaScript代码，所有从数据采集脚本得到的数据均可使用对应于此数据采集中的对象名作为变量名进行验证，若验证失败则可调用warning.send("变量名", "警告信息")来发送警告，若不需要警告则保留此脚本为空<br />
            例如要对上例中的cpu的idle小于10时的情况发出警报，则验证代码如下：<br />
            <pre>
if (cpu__idle < 10) {
    warning.send("cpu__idle", "CPU is too busy!!!");
}
            </pre>
            </p>
            </div>
            <table>
                <tr>
                    <td class="input-table-col">监控项名</td><td><html:text property="name" styleId="name" styleClass="itemInput" /></td>
                </tr>
                <tr>
                    <td class="input-table-col">采集时间间隔（秒钟）</td><td><html:text property="timeInterval" styleId="timeInterval" styleClass="itemInput" /></td>
                </tr>
                <tr>
                    <td class="input-table-col">数据采集脚本</td><td><html:file property="cscript" styleId="cscript" />  <div id="downloadScript" style="display:inline;"></div></td>
                </tr>
                <tr>
                    <td class="input-table-col">数据采集命令行</td><td><html:text property="commandLine" styleId="commandLine" styleClass="itemInput" /></td>
                </tr>
                <tr>
                    <td class="input-table-col">数据验证脚本<br /></td><td><html:textarea property="vscript" styleId="vscript" styleClass="itemTextArea" /></td>
                </tr>
                <tr>
                    <td class="input-table-col">警告邮件地址</td><td><html:text property="warningEmail" styleId="warningEmail" styleClass="itemInput" /></td>
                </tr>
                <tr>
                    <td colspan="2" class="submit-button-col"><html:hidden property="iid" value="0" styleId="iid" /><html:submit value="确定" /><html:button property="button" value="取消" styleId="closeItemBox" /></td>
                </tr>
            </table>
        </html:form>
    </dd>
</dl>

<script type="text/javascript">
    <%
    if (currentNode.isConnected()) {
    %>
    itemBox = initBox("lightBox", "addItem", "closeItemBox", null, onShowBox, onCloseItem, null);
    <%
    } else { %>
    $("lightBox").style.display = "none";
    <%
    }
    if (request.getAttribute("showBox") != null) {
    %>
        itemBox.Show();
    <%
    } else {
    %>
        onCloseItem();
    <%
    }
    org.sysmo.server.node.item.ConnectedItem editItem = (org.sysmo.server.node.item.ConnectedItem)request.getAttribute("editItem");
    if (editItem != null) {
        org.sysmo.server.node.item.ItemScript editScript = editItem.getMonitorScript();
    %>
        $("lightBoxTitle").innerHTML = "编辑监控项";
        $("name").value = "<%= org.sysmo.server.util.UtilHelper.encodeJSString(editItem.getName()) %>";
        $("timeInterval").value = "<%= editItem.getRunInterval() %>";
        $("vscript").value = "<%= org.sysmo.server.util.UtilHelper.encodeJSString(editItem.getValidateScript()) %>";
        $("warningEmail").value = "<%= org.sysmo.server.util.UtilHelper.encodeJSString(editItem.getWarningContect().getEmail()) %>";
        $("commandLine").value = "<%= org.sysmo.server.util.UtilHelper.encodeJSString(editScript.getCommandLine()) %>";
        $("cscript").value = "";
        $("downloadScript").innerHTML = "<a href=\"GetScript.do?iid=<%= editItem.getID() %>\">下载原脚本</a>";
        $("iid").value = "<%= editItem.getID() %>";
        itemBox.Show();
    <%
    }
    %>
</script>

<!-- Do you want remove this backlinks? Look at www.nuviotemplates.com/payment.php -->
<p id="copy"><a href="http://www.nuviotemplates.com/">Free web templates</a> presented by <a href="http://www.qartin.cz/">QARTIN</a> &ndash; Our tip: <a href="http://www.thinline.cz/">Webdesign</a>, <a href="http://www.cesky-hosting.cz/">Webhosting</a></p>
<!-- Do you want remove this backlinks? Look at www.nuviotemplates.com/payment.php -->

</body>
</html>
